<template>
  <div class="userInfo">
    <div class="user">
        <div class="name">{{ userInfo.yb_realname }}</div>
        <div class="college">
          <div>学号：<span>{{ userInfo.yb_studentid }}</span></div>
          <div>
            <span v-if="userInfo.yb_collegename.length < 9 && userInfo.yb_collegename !== '云南农业大学'">学院：</span>
            <span>{{ userInfo.yb_collegename }}</span>
          </div>
        </div>
    </div>
    <div class="box">
      <div class="isdao" @click="isdao">报到后点击此处</div>
      <div v-if="promote" class="promote">
        <a :href="baseConfig.promote.link">{{ baseConfig.promote.label }}<span>></span></a>
      </div>
    </div>
    <span class="admin" @click="goToAdmin()">后台管理</span>
  </div>
</template>

<script>
import api from '../api/index'
import cookie from 'js-cookie'

export default {
  data () {
    return {
      promote: true
    }
  },
  computed: {
    userInfo () {
      const info = this.$store.state.userInfo
      return info
    },
    baseConfig () {
      const config = this.$store.state.baseConfig
      if (config.promote) {
        return this.$store.state.baseConfig
      } else {
        return { promote: {} }
      }
    }
  },
  methods: {
    goToAdmin () {
      console.log('goto')
      location.href = 'http://49.235.166.90:9527/adm/?token=' + cookie.get('token')
    },
    isdao () {
      const self = this
      this.$confirm({
        title: '再次确认已完成现场报道',
        okText: '确定',
        cancelText: '点错啦',
        width: '300px',
        maskClosable: true,
        onOk: async function () {
          const res = await api.report.findByStuNo({ stuNo: self.userInfo.yb_studentid })
          if (res.code === 0) {
            if (res.data.isdao) {
              self.$message.success('已完成易班报道了哦~')
            } else {
              const sureRes = await api.report.reportSure({ stuNo: self.userInfo.yb_studentid })
              if (sureRes.code === 0) {
                self.$message.success('成功完成易班报道~')
                await api.report.reportCollege({ college: self.userInfo.yb_collegename })
              }
            }
          } else {
            self.$message.info('未完成易班认证或高年级同学无法点击哦~')
          }
        }
      })
    }
  }

}
</script>

<style>
  .ant-modal .ant-modal-content .ant-modal-body {
    padding: 30px 15px;
  }

  .ant-modal-confirm-body-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  .ant-modal-confirm-btns button {
    margin: 0px 15px;
  }

</style>

<style scoped>
  .userInfo{
    margin-top: 94%;
    margin-left: auto;
    margin-right: auto;
    width: 85%;
    height: 17%;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    justify-content: center;
  }

  .user{
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    color: #fff;
    text-shadow: 0 0 3px rgb(194, 104, 44);
    font-family: arial;
  }

  .admin {
    display: none;
  }

  /* 适配iphone: 11; */
  @media all and (min-width: 375px) and (min-height: 812px) {
    .userInfo{
      margin-top: 94%;
      height: 17%;
    }
  }

   /* 适配iphone: 11; */
  @media all and (min-width: 411px) and (min-height: 731px){
    .userInfo{
      margin-top: 96%;
      height: 17%;
    }
  }

  @media screen and (max-width: 411px) and (max-height: 823) {
    .user {
      font-size: 18px;
    }
  }

  .user .name {
    font-size: 1.3em;
    line-height: 50px;
    margin-left: 20px;
    height: 50px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
  }

  .user .college{
    margin-left: 20px;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }

  .userInfo .box {
    display: flex;
    justify-content: center;
  }

  .userInfo .isdao{
    margin-top: 10px;
    text-align: center;
    line-height: 28px;
    width: 50%;
    background-color: rgba(228, 228, 228, 0.4);
    color: rgb(66, 66, 66);
    border-radius: 10px;
  }

  .userInfo .promote {
    margin-left: 20px;
    margin-top: 10px;
    text-align: start;
    line-height: 28px;
    color: rgb(0, 23, 66);
  }

  .userInfo .promote a {
    color: #333;
  }

  @media screen and (max-width: 360px) {
    .user {
      font-size: 14px;
    }
  }

  @media all and (max-width: 320px){
    .user {
      font-size: 14px;
    }

    div.user .name {
      font-size: 1.3em;
      line-height: 50px;
      margin-left: 10px;
      max-width: 110px;
    }

    div.user .college{
      margin-left: 12px;
      height: 100%;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
    }

    .userInfo .box {
      font-size: 14px;
    }

    .userInfo .isdao {
      margin-top: 5px;
      line-height: 24px;
    }

    .userInfo .promote {
      line-height: 24px;
      margin-top: 5px;
    }
  }

   @media all and (min-width: 540px) {
     .userInfo {
       margin-top: 97%;
       font-size: 1.2rem;
     }
   }

  @media all and (min-width: 768px) {
    .userInfo {
      margin-top: 97%;
      font-size: 1em;
      width: 480px;
    }

    .user .isdao {
      line-height: 28px;
    }
  }

  @media all and (min-width: 1024px) {
    .userInfo {
      margin-top: 97%;
      width: 480px;
      font-size: 1em;
      margin-bottom: 100px;
    }
  }

  @media screen and (min-width: 1200px) {
    .userInfo{
      margin-top: 97%;
      margin-bottom: 100px;
      width: 480px;
      font-size: 1em;
    }
    .admin {
      display: block;
      position: fixed;
      top: 20px;
      left: 20px;
      color: white;
      cursor: pointer;
    }
    .admin:hover {
      text-decoration: underline;
    }
  }

</style>
